// 重构组织列表
import { deepCopy } from '@/utils/tools'
 
export default (ctx, next) =>{
    
    let {params:resData, store} = ctx;
    let companyNames = Object.keys(resData);
    let organizationList = [];
    let { build, total }  = store.getters['organizationStore/departmentFomatConf']

    companyNames.forEach(companyName =>{

        let company = resData[companyName];
        let { _company } =  build({company, department: null})
        
        // 添加自定义属性
        Object.assign(company, _company)
        
        // 添加部门结构
        company['children'].forEach(department =>{

            let { _department } =  build({company, department})
            
            // 添加自定义属性
            Object.assign(department, _department)
        
        })
        
        organizationList.push(company)
        
    })

    // 总公司,添加分公司结构
    total.children = organizationList;
    
    ctx.params = [ total ]

    next ()
}
